// components/sharePop/sharePop.js
import LoginStore from '../../pages/login/store.js';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    resourceInfo: {
      type: String,
      value: '',
      observer: function (newVal, oldVal, changedPath) {

      }
    },
    needPoster: {
      type: Boolean,
      value: true,
      observer: function (newVal, oldVal, changedPath) {

      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    sharePopStyle:{
      cls:'sharePopStyle'
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    changeAccount:function(){
      this.cancel();
      if (this.properties.resourceInfo === 'weixin'){
        wx.navigateTo({
          url: '/pages/login/login?loginType=account',
        })
      }else{
        wx.showLoading({
          mask: true,
          title: '验证用户信息',
          success: function () {
            LoginStore.isNewUser({
              callback: ()=>{
                wx.hideLoading();
                wx.reLaunch({
                  url: '/pages/userInfo/userInfo?userId=' + LoginStore.userInfo.userId
                })
              },
              loginId: LoginStore.openId,
              loginType: 'weixin',
              unionId: LoginStore.unionId,
              pageInfo: {}
            });
          }
        })
      }
      
    },
    makePoster:function(){
      this.cancel("makePoster");
    },
    cancel: function (p){
      let myEventDetail = {};
      if (p && p ==='makePoster'){
        myEventDetail.makePoster = true;
      };
      let childs = this.selectComponent("#popWindow");
      childs.closePop();
      setTimeout(() => {
        this.triggerEvent('closeSharePop', myEventDetail,{});
      }, childs.data.time)
    }
  }
})
